<?php

/**
 * Flash相关控制器
 * @author Samuel
 */
class FlashController extends BaseController {

    /**
     * 初始化
     * @since  12/06/01
     * @author Samuel
     * @return array
     * <pre>
     *  'loadImgList'   => array(
     *       'img_class:lesson:testId:stepId:imgid' => array(
     *              'imgId'     => string,  //img_class:lesson:step:id
     *              'posX'      => float,   //x轴坐标
     *              'posY'      => float,   //y轴坐标
     *              'url'       => string,  //图片地址
     *          ),
     *          ...
     *      ),
     * </pre>
     */
    public function init() {
        
        Flash_Info::getInstance($this->uId)->setToCache($this->classId,  $this->lessonId,  $this->testId);
        $flashInfoList = Flash_Info::getInstance($this->uId)->getCache();
//        print_r($flashInfoList);echo '<br>';
        $loadImg = $flashInfoList[$this->classId][$this->lessonId][$this->testId]['loadImgList'];
        return array(
                'id' => array(
                    'classId'   =>  $this->classId,
                    'lessonId'  =>  $this->lessonId,
                    'testId'    =>  1,
                ),
                'loadImgList'   =>  $loadImg
            );
    }

    /**
     * 运行相关
     * @since  12/06/01
     * @author Samuel
     * @return array
     * <pre>
     *  'step'          => int  //步骤id
     *  'isend'         => boolean  //是否结束0：未结束，1：结束
     *  'addImgList'    => array(
     *      'img_class:test:step:id',
     *      ...
     *  ),
     *  'addSpList'     => array(
     *       'sp_class:test:step:id' => array(
     *          'spId'      => string,  //sp_class:lesson:step:id
     *          'posX'      => float,   //x轴坐标
     *          'posY'      => float,   //y轴坐标
     *          'height'    => float,   //高度
     *          'width'     => float,   //宽度
     *      ),
     *      ...
     *  ),
     *  'addTextList'   => array(
     *       'text_class:test:step:id' => array(
     *              'textId'    => string,  //text_class:lesson:step:id
     *              'posX'      => float,   //x轴坐标
     *              'posY'      => float,   //y轴坐标
     *              'height'    => float,   //高度
     *              'width'     => float,   //宽度
     *              'type'      => string,  //text控件类型 : todo
     *              'restrict'  => string,  //内容限制 : todo
     *              'matchStr'  => string,  //匹配用户输入的字符串跟数据库是否一致
     *          ),
     *          ...
     *  ),
     *  'addListenList' => array(
     *      listen_class:test:step:id => array(
     *          'stepId'    => int,     //下一步
     *          'type'      => sting,   //类型 : todo
     *          'listenId'  => string,  //listen_class:lesson:step:id
     *      ),
     *      ...
     *  ),
     *  'removeImgList'   => array(
     *      'img_class:test:step:id',
     *      ...
     *  ),
     *  'removeTextList'     => array(
     *      'text_class:lesson:step:id',
     *      ...
     *  ),
     *  'removeListenList'     => array(
     *      'listen_class:lesson:step:id' => type:string : todo
     *      ...
     *  ),
     *  'removeSpList'      => array(
     *      'sp_class:test:step:id',
     *      ...
     *  )
     *  
     * </pre>
     */
    public function run() {
        $_SESSION['uId'] = 1;
        $flashInfoList = Flash_Info::getInstance($_SESSION['uId'])->getCache();
        
        $classId = key($flashInfoList);
        $lessonId = key($flashInfoList[$classId]);
        $testId = key($flashInfoList[$classId][$lessonId]);
        $stepId = $this->getParamInt('stepId',true , true );
        
        
        $addImgList = $flashInfoList[$classId][$lessonId][$testId]['addImgList'];//添加图片列表
//        print_R($addImgList);
        $addImgarray = array ();
        foreach ($addImgList as $key => $value) {
            $arrStep = explode(':', $key);
                if ( $arrStep['3'] == $stepId ) {
                    $addImgarray = array ($key =>$value);
                }
        }
        
        
        $addSpList = $flashInfoList[$classId][$lessonId][$testId]['addSpList'];//添加sp列表
//        print_r($addSpList);
        $addSparray = array ();
        foreach ($addSpList as $key => $value) {
            $arrStep = explode(':', $key);
                if ( $arrStep['3'] == $stepId ) {
                    $addSparray = array ($key =>$value);
                }
        }
        
        
        $addTextList = $flashInfoList[$classId][$lessonId][$testId]['addTextList'];//添加text列表
//        print_r($addTextList);
        $addTextarray = array ();
        foreach ($addTextList as $key => $value) {
            $arrStep = explode(':', $key);
                if ( $arrStep['3'] == $stepId ) {
                    $addTextarray = array ($key =>$value);
                }
        }
        
        
        $addListenList = $flashInfoList[$classId][$lessonId][$testId]['addListenList'];//添加listen列表
//        print_r($addListenList);
        $addListenarray = array ();
        foreach ($addListenList as $key => $value) {
            $arrStep = explode(':', $key);
                if ( $arrStep['3'] == $stepId ) {
                    $addListenarray = array ($key =>$value);
                }
        }        
        
        
        $removeImgList = $flashInfoList[$classId][$lessonId][$testId]['removeImgList'];//删除图片类表
//        print_r($removeImgList);
        $removeImgarray = array ();
        foreach ($removeImgList as $key => $value) {
            $arrStep = explode(':', $key);
                if ( $arrStep['3'] == $stepId ) {
                    $removeImgarray = array ($key =>$value);
                }
        }        
        
        
        
        $removeSpList = $flashInfoList[$classId][$lessonId][$testId]['removeSpList'];//删除sp列表
//        print_r($removeSpList);
        $removeSparray = array ();
        foreach ($removeSpList as $key => $value) {
            $arrStep = explode(':', $key);
                if ( $arrStep['3'] == $stepId ) {
                    $removeSparray = array ($key =>$value);
                }
        }
               
        
        
        
        $removeTextList = $flashInfoList[$classId][$lessonId][$testId]['removeTextList'];//删除text列表
//        print_r($removeTextList);
        $removeTextarray = array ();
        foreach ($removeTextList as $key => $value) {
            $arrStep = explode(':', $key);
                if ( $arrStep['3'] == $stepId ) {
                    $removeTextarray = array ($key =>$value);
                }
        }
        
        
        $removeListenList = $flashInfoList[$classId][$lessonId][$testId]['removeListenList'];//删除listen列表
//        print_r($removeListenList);
        $removeListenarray = array ();
        foreach ($removeListenList as $key => $value) {
            $arrStep = explode(':', $key);
                if ( $arrStep['3'] == $stepId ) {
                    $removeListenarray = array ($key =>$value);
                }
        }
        
        return array (
            'addImgList'=>$addImgarray,
            'addSpList'=>$addSparray,
            'addTextList'=>$addTextarray,
            'addListenList'=>$addListenarray,
            
            'removeImgList'=>$removeImgarray,
            'removeSpList'=>$removeSparray,
            'removeTextList'=>$removeTextarray,
            'removeListenList'=>$removeListenarray
        );
    }

    /**
     * TODO：结束后的操作
     * @since  12/06/01
     * @author Samuel
     * @return array
     */
    public function end() {
        return array();
    }

}

?>